package com.fhz.mvvm

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.fhz.loginmvvm.callback.ApiSuccessResponse
import com.fhz.mvvm.adapter.UserAdapter
import com.fhz.mvvm.databinding.ActivityMainBinding
import com.fhz.mvvm.viewmodel.UserViewModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    lateinit var binding: ActivityMainBinding

    val userViewModel: UserViewModel by viewModels()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.userRv.layoutManager = LinearLayoutManager(this)

        userViewModel.login("q1","1").observe(this){
            println(it)
            val apiSuccessResponse = it as ApiSuccessResponse
            binding.userRv.adapter = UserAdapter(apiSuccessResponse.body.data)

            userViewModel.insertUser(apiSuccessResponse.body.data)
        }
    }
}